﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

using ADO_QLNS.Utils;

namespace ADO_QLNS
{
    public class ADOHelper
    {
        private AbstractFactory_ADO _DataProvider;

        public ADOHelper(AbstractFactory_ADO provider)
        {
            _DataProvider = provider;
        }

        public AbstractFactory_ADO DataProvider
        {
            get { return _DataProvider; }
            set { _DataProvider = value; }
        }

        public void Connect()
        {
            _DataProvider.CreateConnection();
            _DataProvider.Connection.Open();
        }

        public void Disconnect()
        {
            _DataProvider.Connection.Close();
        }

        public IDataReader exeQuery(string sqlString)
        {
            _DataProvider.CreateCommand(sqlString);
            return _DataProvider.Command.ExecuteReader();
        }

        public void exeNonQuery(string sqlString)
        {
            _DataProvider.CreateCommand(sqlString);
            _DataProvider.Command.ExecuteNonQuery();
        }

        public object exeScalar(string sqlString)
        {
            _DataProvider.CreateCommand(sqlString);
            return _DataProvider.Command.ExecuteScalar();
        }
    }
}
